define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'flow/test/index',
                    add_url: 'flow/test/add',
                    edit_url: 'flow/test/edit',
                    del_url: 'flow/test/del',
                    multi_url: 'flow/test/multi',
                    table: 'test',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'admin_id', title: __('Admin_id')},
                        {field: 'type_text', title: __('Type')},
                        {field: 'title', title: __('Title')},
                        {field: 'description', title: __('Description')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('回退修改'),"0":__('保存中'),"1":__('流程中'),"2":__('通过')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                          buttons: [
                            {
                              name: 'status',
                              icon: 'fa fa-sticky-note',
                              title: __('发起工作流'),
                              text:'发起工作流',
                              url: 'flow/flow/wfstart/wf_type/{type}/wf_title/{title}',
                              classname: 'btn btn-xs btn-success btn-dialog ',
                              hidden: function (value, row, index) {
                                if(value.status == 0)
                                {
                                  return false;
                                }
                                return true;
                              }
                            },

                          ],
                          formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});